package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_RECOVER_ENERGY_FROM_CROSS,desc = "使用道具恢复体力")
public class DouLuoDaLuRecoverEnergyCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuRecoverEnergyRespMsg respMsg = DouLuoDaLuProto.DouLuoDaLuRecoverEnergyRespMsg.parseFrom(packet.getBytes());

        String consume = DouLuoDaLuMgr.getConfig().ENERGY_ITEM_ID + "=" + respMsg.getNum();
        // 预扣除
        player.getModule(PreReduceModule.class).restorePreReduce(consume);

        if(respMsg.getRet() == 0){
            player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(consume), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuUserEnergyConsume);

        }

        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_RECOVER_ENERGY, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
